<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<ul><li id="li1"></li><li></li><li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
<script>
    // 在页面上有一个ul标签，其中有10个li标签，使用JS将li标签中的内容改为其索引值
    let lis = document.getElementsByTagName("li");
    for (let i = 0; i < lis.length; i++) {
        lis[i].textContent = i;
    }
    // 只允许获取ul标签
    let ul = document.getElementsByTagName("ul")[0];
    console.log(ul);
    console.log(ul.childNodes.length);
    for (let i = 0; i < ul.childNodes.length; i++) {
        // console.log(ul.childNodes[i].nodeType);
        if (ul.childNodes[i].nodeType == 1)
            ul.childNodes[i].textContent = i + "li";
    }
    // 只能获取第一个li标签
    let li1 = document.getElementById("li1");
    li1.textContent = "0";
    let i = 1;
    let ns = li1.nextSibling;
    while (i < 10) {
        ns.textContent = i;
        i++;
        ns = ns.nextElementSibling;
    }

    console.log(ul.children.length);
    for (let i = 0; i < ul.children.length; i++) {
        ul.children[i].textContent = "cl" + i;
    }
</script>
</body>
</html>